package com.example.administrator.yunniuusedcar.fragment.ShoppInfo_Fragment;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.administrator.common.base.BaseFragment;
import com.example.administrator.common.base.Global;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.adapter.ShopInfon_JBAdapter;
import com.example.administrator.yunniuusedcar.model.mode_benn.IHttpService;
import com.example.administrator.yunniuusedcar.model.mode_benn.RanCarXiangQingBean;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;

import okhttp3.Call;

/**
 * Created by Administrator on 2017/12/8.
 *  综合排序  . 商品详情
 */

public class JiBenInfoFragment extends BaseFragment {

    private ImageView JiBenCarPager;
    private TextView tvNumPager;
    private TextView tvSelectdeCarInfo;
    private TextView tvCarYuan;
    private TextView JiFenJia;
    private TextView HuiYuanJia;
    private TextView tvShiChangJia;
    private RadioButton RB2017Kuan;
    private RadioButton RB2018Kuan;
    private FrameLayout flKuanShiXianQing;
    private RadioGroup RG;
    private android.support.v7.widget.RecyclerView recyclerView61;
    private ArrayList listDatas;
    private int resultID;

    @Override
    public int getLayoutRes() {
        return R.layout.item_recycleview2;
    }

    @Override
    public void initView() {
        initFindViewId();
        loadDatas();
        Intent intent = getActivity().getIntent();

        int trm = intent.getIntExtra("RanCarid",0);  //
        System.out.println("aaaaaaaaaaa----aaaaaa "+trm);
        //汽车列表id
        resultID = trm;//Integer.valueOf(trm);

        recyclerView61 = (RecyclerView) findView(R.id.recycler_view6);
        recyclerView61.setLayoutManager(new LinearLayoutManager(getContext()));
    }

    private void initFindViewId() {

        listDatas = new ArrayList();
        RG = (RadioGroup) findView(R.id.radio);   // 单选组

//        JiBenCarPager = findView(R.id.JiBenCarPager);    // holder 里用了
//        tvNumPager = (TextView) findView(R.id.tv_NumPager);
//        tvSelectdeCarInfo = (TextView) findView(R.id.tv_SelectdeCarInfo);
//        tvCarYuan = (TextView) findView(R.id.tv_CarYuan);
//        JiFenJia = (TextView) findView(R.id.JiFenJia);
//        HuiYuanJia = (TextView) findView(R.id.HuiYuanJia);
//        tvShiChangJia = (TextView) findView(R.id.tv_ShiChangJia);   // 市场价格

        RB2017Kuan = (RadioButton) findView(R.id.RB_2017Kuan);      // 2017款
        RB2018Kuan = (RadioButton) findView(R.id.RB_2018Kuan);     // 2018款
        flKuanShiXianQing = (FrameLayout) findView(R.id.fl_KuanShiXianQing);

    }



    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    //获取方式：
//    Intent intent = getActivity().getIntent();
//
//    String trm = intent.getStringExtra("RanCarid");  //空指针
//    int resultID = Integer.valueOf(trm); //汽车列表id

    private void loadDatas() {
//
        String ul = IHttpService.HOST_URL + "Car/getcarInfo";    // 随机汽车 详情
        //String.valueOf(resultID)  car_id
        OkHttpUtils.post().url(ul).addParams("sign",IHttpService.SignVal).addParams("car_id", String.valueOf(resultID)).build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Global.showToast("RanCarInfo ERRor" + e);
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        System.out.println("-----====----------A" + response.toString());

                        Global.showToast("11111111" + response);
                        RanCarXiangQingBean ranCarInfoBean = new Gson().fromJson(response, RanCarXiangQingBean.class);
                        if(ranCarInfoBean.code==1){
                            listDatas.add(ranCarInfoBean);
                        }
                        ShopInfon_JBAdapter shopInfonJbAdapter = new ShopInfon_JBAdapter(getContext(),listDatas);
                        recyclerView61.setAdapter(shopInfonJbAdapter);
                    }
                });
    }
}
